import { ElNotification, ElButton } from 'element-plus';
// import router from '@/router'; // 导入路由实例
const notification = {
  state: {
    activeNotification: null,
  },
  mutations: {
    setNotification(state, notification) {
      if (state.activeNotification) {
        state.activeNotification.close();
      }
      state.activeNotification = notification;
    },
  },
  actions: {
    showSampleNotification({ commit }, res) {
      const notifyRef = { value: null };
      const notification = ElNotification({
        title: '取样通知',
        duration: 0, // 设置为0则不自动关闭
        max: 1,
        message: h('div', null, [
          h('p', null, '您有' + res.data.data + '份样本留取任务待处理！'),
          h(
            'div',
            { style: 'text-align: right; margin-top: 10px;' },
            h(
              ElButton,
              {
                type: 'primary',
                size: 'small',
                onClick: () => {
                  // 路由跳转
                  router.push({ path: '/samplingnotice/samplingNotice' });

                  // 关闭通知
                  if (notifyRef.value) {
                    notifyRef.value.close();
                  }
                },
              },
              '查看详情'
            )
          ),
        ]),
        type: 'warning',
      });
      notifyRef.value = notifyInstance;
      commit('setNotification', notification);
    },
  },
};
export default notification;
